Repository navigation
feat(ios): serve Vite dev over the USB CoreDevice tunnel - #6210
Draft
edusperoni wants to merge 1 commit into
Draft
edusperoni wants to merge 1 commit into
edusperoni wants to merge 1 commit into
Conversation
A USB-connected iOS 17+ / visionOS device reaches the Mac over a CoreDevice tunnel (a utun with an fdXX::/64 ULA pair) without Wi-Fi and without the Local Network prompt. The tunnel only exists while a client holds it, and every new tunnel gets a new address. For a Vite HMR session whose only target of a platform is such a device, the run controller now opens the tunnel before prepare: it holds it with `devicectl device notification observe` for the session, reads the device's end from `devicectl list devices`, and takes the Mac's address in the same subnet from the local interfaces. The bundler passes that address to both Vite children as NS_HMR_HOST, so bundle.mjs and the dev server use the tunnel origin. The holder is killed when the device leaves the session or the CLI exits; if it dies on its own the CLI warns that the app lost the dev server. Only an @nativescript/vite that lists the platform under nativescriptCli.singleProcessDev gets the tunnel: older releases bind the dev server to NS_HMR_HOST and put an IPv6 literal into URLs unbracketed. A user-set NS_HMR_HOST, simulators, Wi-Fi or network-paired devices, iOS < 17, a missing devicectl, a tunnel that does not come up and sessions with more than one device of the platform also keep the LAN host from @nativescript/vite, with one trace line.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
Important
HMR over the tunnel needs the websockets fix from valor-software/nativescript-plugins#27, which is not released yet. With
@valor/nativescript-websockets2.0.3 the app loads all of its modules over the tunnel, but the Vite HMR socket never connects: the iOS handshake sends the IPv6 host unbracketed, and Vite rejects the upgrade. Until #27 ships, a session with one USB iPhone gets no hot updates by default. The only way out today is settingNS_HMR_HOSTby hand (for example to the LAN address).What is the current behavior?
utunwith anfdXX::/64ULA pair) that an app can reach without Wi-Fi and without the prompt. Nothing uses it.What is the new behavior?
The CLI opens the device's CoreDevice tunnel itself and keeps it open for the session. Nothing keeps one open otherwise: the CLI's own device channel (ios-device-lib) never opens one, a tunnel closes about 5-10 s after its last client goes away, and every new tunnel gets a new address.
devicectlreportstransportType: wired), and the installed@nativescript/vitelists the platform undernativescriptCli.singleProcessDev. Older releases bind the dev server toNS_HMR_HOSTand put an IPv6 literal into URLs without brackets, so they keep today's behavior.xcrun devicectl device notification observe --device <udid> …with a one-year session timeout to hold the tunnel. It then pollsdevicectl list devices --json-output(up to 10 s) until the device'stunnelStateisconnected.tunnelIPAddressthere is the device's end (fdXX::1). The Mac's end is the local interface address in the same subnet (fdXX::2on theutun), read fromos.networkInterfaces().NS_HMR_HOSTfor that platform only, sobundle.mjsboots fromhttp://[fdXX::2]:<port>. Other platforms in the same CLI process are unaffected.ns rundoes not add a replugged device back to a running session, so the new tunnel address never has to be applied to a running dev server.NS_HMR_HOSTalways wins, and no tunnel is opened then. Simulators, Wi-Fi or network-paired devices, iOS < 17, non-macOS hosts, a missingdevicectland tunnels that do not come up all keep the LAN host from@nativescript/vite, with one trace line. A session with more than one device of the platform also stays on LAN: one dev server bakes one origin intobundle.mjs, and a tunnel address is reachable only from its own device (and not from the Mac itself, so not from a simulator either). Android is untouched.Verification
Using the USB tunnel to … (Mac address fdXX::2).bundle.mjscontains onlyhttp://[fdXX::2]:5173.fdXX::1, none from the LAN..vuefile producedhmr update, and the device fetched the updated module over the tunnel. This was with the websocketsplatform updatecommand #27 build swapped in, see above.devicectlholder behind.devicectl: the address is stable while any holder lives, and two overlapping holders share one tunnel. It closes 5-10 s after the last holder exits. A new holder gets a new/64.vite build --watch+vite serve) path, which is unit-tested only, a locked device and Mac sleep.devicectlparsing, the Mac-side address, holder lifecycle), the run controller's single-target rule and close-on-stop, theNS_HMR_HOSThand-off and the package capability check.Stacked on #6209. Pairs with NativeScript/NativeScript#11650.